import {submitLoginRequest} from '../http/httpFunction'

export default {
    namespaced:true,
    actions:{
        async submitLoginRequest(content,val){
            if(val.username === ''|| val.password === ''){
                content.commit('SUBMITLOGINREQUEST','账号或密码不可为空')
            }else{
                const result = await submitLoginRequest(val.username,val.password)
                content.commit('SUBMITLOGINREQUEST',result.data.msg)
                const token = result.data.data.token
                if(token){
                    window.sessionStorage.setItem('token',token)
                }else{
                    window.sessionStorage.setItem('token','')
                }
            }
        }
    },
    mutations:{
        SUBMITLOGINREQUEST(state,val){
            state.loginMsg = val
            state.upBoxisShow = true
            setTimeout(()=>{
                state.upBoxisShow = false
                state.loginMsg = ''
            },1000)
        }
    },
    state:{
        loginMsg:"",
        upBoxisShow:false,
    }
}